package com.orange.cetback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orange.cetback.pojo.entity.MedalLevel;
import com.orange.cetback.pojo.entity.UserMedal;
import com.orange.cetback.mapper.UserMedalMapper;
import com.orange.cetback.service.MedalLevelService;
import com.orange.cetback.service.UserMedalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenenjun
 * @since 2025-04-02
 */
@Service
public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal> implements UserMedalService {
    @Autowired
    private MedalLevelService medalLevelService;

    @Override
    public List<MedalLevel> getUserMedalList(Long userId) {
        List<MedalLevel> list = medalLevelService.list();
        LambdaQueryWrapper<UserMedal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserMedal::getUserId, userId);
        List<UserMedal> userMedalList = this.baseMapper.selectList(wrapper);
        for (MedalLevel medalLevel : list) {
            for (UserMedal userMedal : userMedalList) {
                if (medalLevel.getMedalId().equals(userMedal.getMedalId())) {
                    medalLevel.setIsGranted(true);
                }
            }
        }
        return list;
    }
}
